from django.db import models
from apps.user.models import User

class PayOrder(models.Model):
    PAY_TYPE_CHOICES = [
        ("alipay", "支付宝"),
        ("wechat", "微信支付"),
    ]
    STATUS_CHOICES = [
        ("pending", "待支付"),
        ("paid", "已支付"),
        ("failed", "支付失败"),
        ("closed", "已关闭"),
    ]

    order_no = models.CharField(max_length=64, unique=True, verbose_name="订单号")
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="金额")
    description = models.CharField(max_length=255, verbose_name="商品描述")
    pay_type = models.CharField(max_length=16, choices=PAY_TYPE_CHOICES, verbose_name="支付类型")
    status = models.CharField(max_length=16, choices=STATUS_CHOICES, default="pending", verbose_name="支付状态")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        verbose_name = "支付订单"
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.order_no} - {self.user.username} - {self.amount}"
